#pragma once

#include <memory>
#include <string>
#include <vector>
#include <map>
#include "CLogField.h"

class CTableField
{
public:
	CTableField()
				: m_fieldName(""), m_fieldType(EFieldType::EFieldTypeUnknown), m_fieldSize(0)
	{
	}
	CTableField(const std::string& fieldName, EFieldType type, int fieldSize = 0)
		: m_fieldName(fieldName), m_fieldType(type), m_fieldSize(fieldSize)
	{}
	
	// Copy constructor
	CTableField(const CTableField& other)
		: m_fieldName(other.m_fieldName), m_fieldType(other.m_fieldType), m_fieldSize(other.m_fieldSize)
	{}
	
	~CTableField() = default;

	std::string getFieldName() const	{ return m_fieldName; }		
	EFieldType getFieldType() const	{ return m_fieldType; }
	int getFieldSize() const { return m_fieldSize; }

private:
	std::string m_fieldName;
	EFieldType m_fieldType;
	int m_fieldSize;
};

enum ETableType
{
	TableTypeUnknown = 0,
	TableTypeAppend,
	TableTypeUpAppend,
	TableUpdate,
	TableTypeAppendWithCounter,
	TableTypeOver,
};

class CTableConfigure
{
public:
	CTableConfigure();
	void setTableName(const std::string& tableName);
	std::string getTableName() const;
	
	void setKeyFields(const std::vector<std::string>& keyFields);
	void setValueFields(const std::vector<std::string>& valueFields);

	void setTableField(CTableField field);

	std::map<std::string, CTableField>& getTableFieldTypeMap();

	std::vector<std::string> getKeyFields() const;
	std::vector<std::string> getValueFields() const;

	int getUpLoadRecordCount() const;
	int setUpLoadRecordCount(int size);

	uint64_t getMaxBanchSize() const;
	void setMaxBanchSize(uint64_t size);

	int getMaxFailedCount();
	void setMaxFailedCount(int nCount);

public:
	std::string m_tableName; // Table name
	std::vector<std::string> m_uKeyFields; 
	std::vector<std::string> m_uValueFields;

	std::map<std::string, CTableField> m_TableFieldTypeMap; // Field name to type mapping

	int m_nUpLoadBatchSize, m_maxFailedCount;

	uint64_t m_nMaxBatchSize; // Maximum batch size in bytes
};

typedef std::shared_ptr<CTableConfigure> CTableConfigurePtr;
